﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using CreatureSoft.Hoot.Service.DocumentManagent;
using CreatureSoft.Hoot.Web.Models;
using CreatureSoft.Hoot.Domain.DocumentManagent;
using AutoMapper;

namespace Hoot.Web.Controllers
{
    public class FolderController : Controller
    {
        private readonly IFolderService folderService;

        public FolderController(IFolderService folderService)
        {
            this.folderService = folderService;
        }  
        
        public ActionResult Index()
        {
            return View();            
        }

        public ActionResult GetFolders(int parentId)
        {
            IList<Folder> folders = folderService.GetFoldersByParentId(parentId);

            IList<FolderModel> result = Mapper.Map<IList<Folder>, IList<FolderModel>>(folders);

            return Json(result);            
        }

        public ActionResult AddFolder(FolderModel folderVM)
        {
            Folder folder = Mapper.Map<FolderModel, Folder>(folderVM);
            folderService.CreateFolder(folder);

            return Json(folder);
        }

    }
}
